package com.example.hellodemo.broadcast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.hellodemo.R;

public class Broad2Activity extends AppCompatActivity {
    private Button sendBtn;
    private EditText editText;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_broad2);
        sendBtn = findViewById(R.id.broad3);
        sendBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (editText.getText().toString().length() != 0){
                    // 发送消息
                    Intent intent = new Intent("updateText");
                    intent.putExtra("title",editText.getText().toString());
                    LocalBroadcastManager.getInstance(Broad2Activity.this).sendBroadcast(intent);
                }
            }
        });

        editText = findViewById(R.id.broad4);
        
    }
}
